﻿using Core.Framework.CommonExceptions;
using Core.Framework.CommonResults;
using Microsoft.Extensions.DependencyInjection;

namespace Core.Framework.CommonControllers;

public static class CommonControllersServiceCollectionExtensions
{
    /// <summary>
    /// 1、实现CommonController模块
    /// </summary>
    /// <param name="services"></param>
    /// <returns></returns>
    public static IServiceCollection AddCommonControllers(this IServiceCollection services) 
    {
        services.AddControllers(options => {
            // 1、配置CommonResultFilter
            options.Filters.Add<CommonResultFilter>();
            // 2、配置CommonExceptionFilter
            options.Filters.Add<CommonExceptionFilter>();
        }).AddJsonOptions(options => {
            // 3、配置通用Json格式
            options.JsonSerializerOptions.PropertyNamingPolicy = null;
        });

        return services;
    }
}
